<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改元素样式</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            background: pink;
        }
        .change{
            background-color: #bfa;
            width: 500px;
            height: 500px;
        }
    </style>
</head>
<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        div.onclick = function(){
            //1.js通过行内样式方法修改元素样式
            //在修改的东西比较少,修改的功能比较简单的话,这样还比较简单
            // this.style.backgroundColor = 'green';
            // this.style.width = '300px';
            //2.通过类名改样式,适合样式较多,功能复杂的情况
            this.className = 'change';
            //注意!这个会覆盖原先的类名
        }
    </script>
</body>
</html>